package initalize

import (
	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"github.com/apache/rocketmq-client-go/v2/producer"
	"go.uber.org/zap"

	"application/global"
)

func InitProducer() {
	var err error
	global.NewProducer, err = rocketmq.NewProducer(
		producer.WithNsResolver(primitive.NewPassthroughResolver([]string{"127.0.0.1:9876"})),
		producer.WithRetry(2),
	)
	if err != nil {
		zap.S().Error("连接rocker生产者失败！", err.Error())
		return
	}
	//开始生产
	err = global.NewProducer.Start()
	if err != nil {
		zap.S().Error("rocketmq生产者开启失败！", err.Error())
		return
	}
}
